<template>
    <div class="header-title">
        <div class="header_contents">
<!--           <div class="header_titleLeft">
              <div class="head_logo"></div>
               <h3 class="header-title-h3">云南国际现代物流云</h3>
               <p>综合信息服务平台</p>
          </div> -->
          <div class="wy-logo">
            <router-link to="/">
              <!-- <img src="static/img/logo.png" alt=""> -->
              <div class="head_logo"></div>
              <div>
                <h1 class="animated fadeIn">云南国际现代物流云</h1>
                <span class="wy-font-16">综合信息服务平台</span>
              </div>
            </router-link>
          </div>
          <div class="header-title-cont">
            <div class="header-user-left">
              <div class="header-search">
                  <!-- <a-input-search placeholder="运单查询" @search="onSearch" /> -->
                  <span v-if="!loggedIn">
                    <nuxt-link to="/login" class="login">登录</nuxt-link>
                    <nuxt-link to="/register" class="regist">注册</nuxt-link>
                  </span>
                  <a v-if="loggedIn" target="_blank" :href="manageUrl+'#/home'">控制台</a>
              </div>
              <!-- <div class="header-user">
                  <nuxt-link to="/policies/notice">APP二维码</nuxt-link>
                  <nuxt-link to="/policies/notice">加入物流云</nuxt-link>
                  <nuxt-link to="/login" v-if="!loggedIn">控制台</nuxt-link>
                  <a v-if="loggedIn" target="_blank" :href="manageUrl+'#/home'">控制台</a>
              </div> -->
            </div>
            <div v-if="loggedIn" class="header-user-info">
              <a-dropdown>
                <div class="ant-dropdown-link">
                  <div class="header-info-top"></div>
                  <div class="header-info-pic">
                    <img :src="loggedUser&&(manageUrl+'static/avatar/'+loggedUser.avatar)||'./../static/img/index/cheyuanfabu.png'" />
                    <span v-if="info.infoSum">{{info.infoSum}}</span>
                  </div>
                </div>
                <a-menu class="header-user-dropdown" slot="overlay">
                  <a-menu-item >
                    <nuxt-link to="/corp" v-if="loggedUser&&loggedUser.type==2">
											<p class="wy-font-18 wy-text-nowrap">{{loggedUser&&loggedUser.company}}</p>
										</nuxt-link>
                    <p v-if="loggedUser&&loggedUser.type==1" class="wy-font-18 wy-text-nowrap">{{loggedUser&&loggedUser.username}}</p>
                    <p v-if="loggedUser&&loggedUser.type==3" class="wy-font-18 wy-text-nowrap">{{loggedUser&&loggedUser.username}}</p>
                  </a-menu-item>
                  <a-menu-item v-if="loggedUser.type != 3">
                    <a style="margin: 0; padding: 0;" target="_blank" :href="manageUrl+'#/user/auth'">
                      <div class="header-user-dropdown-li wy-font-16">
                          <p>实名认证</p>
                          <span class="wy-col-15" v-if="loggedIn">{{loggedUser.attestationStatusValue}}</span>
                      <!--   <span class="wy-col-15" v-if="loggedIn && loggedUser.attestationStatus == 1">认证中</span>
                        <span class="wy-col-15" v-if="loggedIn && loggedUser.attestationStatus == 2">已认证</span> -->
                      </div>
                    </a>
                  </a-menu-item>
                  <!-- <a-menu-item>
                    <div class="header-user-dropdown-li wy-font-16">
                      <p>我的积分</p>
                      <span>212</span>
                    </div>
                  </a-menu-item>-->
                  <a-menu-item>
                    <!-- <div class="header-user-dropdown-li wy-font-16">
                      <p>我的订单<i></i></p>
                      <span>212</span>
                    </div> -->
                    <a style="margin: 0; padding: 0;" target="_blank" :href="manageUrl+'#/message/station'">
                      <div class="header-user-dropdown-li wy-font-16">
                        <p>站内消息<!-- <i></i> --></p>
                        <span>{{info.infoSum}}</span>
                      </div>
                    </a>
                  </a-menu-item> 
                  <a-menu-item>
                    <div class="header-user-dropdown-li wy-font-16" @click="exitUnsetToken">
                      <p>退出</p>
                    </div>
                  </a-menu-item>
                </a-menu>
              </a-dropdown>
            </div>
          </div>
        </div>
    </div>
</template>
<script>
import { environment } from './../server/environment'
import AuthMixin from '~/mixins/auth'
import Cookies from 'js-cookie'
export default {
  name: "HeaderTop",
  
  mixins: [ AuthMixin ],
  
  components: {
  },
  
  data: () => ({
    manageUrl: environment.MANAGE_URL,
    token: '',
    info: {}
  }),

  created: function() {
      if (process.browser && this.loggedIn) {
        this.getUserinfoCountList();
        // this.token = Cookies.get('token');
        // console.log('token:',this.token)
        // this.$store.dispatch('fetchMessageStats')
      }
      // this.token = Cookies.get('token')
  },

  methods: {
    // 获取统计数据
    async getUserinfoCountList () {
        const res = await this.$store.dispatch('getUserinfoCountList',{})
        if (res.status) {
          this.info = res.data
        }
    },
    
    // 回首页
    gotoIndex () {
        // this.$router.replace('/')
    },
    // 搜索
    onSearch () {

    },
    // 退出登录
    async exitUnsetToken () {
      try {
          await this.$store.dispatch('logout')
          this.$router.replace('/')
      } catch (err) {
          // this.$notify({type: 'error', title: err.msg})
      }
    }
  }
};
</script>

<style lang="scss">
@import "../assets/unit/header.scss";

</style>
